package com.chengfei.spring.cloud.weather.config;

import com.chengfei.spring.cloud.weather.job.WeatherDataSyncJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author chengfei cheng.fei@chinaott.onaliyun.com
 **/
@Configuration
public class QuartzConfig {
    //更新频率
    private static final int TIME = 30;
    //JobDetail
    @Bean
    public JobDetail weatherDataSyncJobDetail(){
        return JobBuilder.newJob(WeatherDataSyncJob.class)
                    .withDescription("weatherDataSyncJob")
                    .storeDurably()
                    .build();
    }
    //Trigger
    @Bean
    public Trigger weatherDataSyncTrigger(){
        SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInMinutes(TIME)
                .repeatForever();
        return TriggerBuilder.newTrigger()
                        .forJob(weatherDataSyncJobDetail())
                        .withIdentity("weatherDataSyncTrigger")
                        .withSchedule(simpleScheduleBuilder)
                        .build();
    }
}
